﻿using System;

using Castle.ActiveRecord;

using Pampa.CRUD.Core;

namespace Demo.Model
{
    [ActiveRecord]
    public class Address : AbstractActiveRecord<Address>, IIdentifiable
    {
        private int id;
        private string street;
        private City city;
        private string number;
        private Customer customer;

        public Address()
        { 
        }
        
        [PrimaryKey]
        public virtual int ID
        {
            get{ return id; }
            set{ id = value; }
        }

        [Property]
        public virtual string Street
        {
            get { return street; }
            set { street = value; }
        }

        [BelongsTo("CityID")]
        public virtual City City
        {
            get { return city; }
            set { city = value; }
        }

        [Property]
        public virtual string Number
        {
            get { return number; }
            set { number = value; }
        }

        [BelongsTo("CustomerID")]
        public virtual Customer Customer
        {
            get { return customer; }
            set { customer = value; }
        }

        #region Miembros de IIdentifiable

        string IIdentifiable.Id
        {
            get { return this.ID.ToString(); }
        }

        #endregion

        /// <summary>
        /// Este metodo hace falta si el Id devuelto por los combos debe parsearse para obtener un objeto id
        /// </summary>
        public static object ParseId(string id)
        {
            return Int32.Parse(id);
        }
    }
}
